#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QSerialPortInfo>
#include <QSerialPort>
#include <QMessageBox>
#include <QTime>
#include <QDateTime>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    SlotsInit();
    GetAvailablePorts(ui->comboBox);

    SetCurrentTime();

    ui->listWidget->setCurrentRow(0);
    ui->listWidget_2->setCurrentRow(0);
    ui->listWidget_3->setCurrentRow(0);
    ui->listWidget_4->setCurrentRow(0);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::SetCurrentTime()
{
  QDateTime now=QDateTime::currentDateTime();
  QString tmp=QString::number(now.date().year()).right(2);
  ui->spinBox_2->setValue(tmp.toInt());

  tmp=QString::number(now.date().month()).right(2);
  ui->spinBox_3->setValue(tmp.toInt());

  tmp=QString::number(now.date().day()).right(2);
  ui->spinBox_4->setValue(tmp.toInt());

  tmp=QString::number(now.time().hour()).right(2);
  ui->spinBox_7->setValue(tmp.toInt());

  tmp=QString::number(now.time().minute()).right(2);
  ui->spinBox_6->setValue(tmp.toInt());

  tmp=QString::number(now.time().second()).right(2);
  ui->spinBox_5->setValue(tmp.toInt());
}

void MainWindow::SlotsInit()
{
    connect(ui->listWidget_3,SIGNAL(itemSelectionChanged()),this,SLOT(ListWidget3_ItemSelectChanged()));
    connect(ui->listWidget_2,SIGNAL(itemSelectionChanged()),this,SLOT(ItemSelectChanged()));
    connect(ui->listWidget,SIGNAL(itemSelectionChanged()),this,SLOT(ListWidget1ItemSelectChanged()));

    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(OpenPort()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(SendReadData()));

    connect(&timer,SIGNAL(timeout()),this,SLOT(SendReadData()));
    connect(ui->checkBox,SIGNAL(clicked()),this,SLOT(CheckBoxChecked()));

    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(ReadAdressData()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(WriteAdressData()));
    connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(WriteGeneralData()));
    connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(BroadCasetTime()));
    connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(BroadCasetTimeByZhiDing()));


}

void MainWindow::GetAvailablePorts(QComboBox * combo)
{
    for(QSerialPortInfo x:QSerialPortInfo::availablePorts())
    {
        combo->addItem(x.portName());
    }
}
//D0
void MainWindow::GetByteArray4(QByteArray & sendData)
{
    if(ui->listWidget->currentRow()==0x00)
        sendData.append(ui->listWidget_4->currentRow()+0x33);
    else if(ui->listWidget->currentRow()==0x02)
    {
        if(ui->listWidget_2->currentRow()<7)
        {
            sendData.append((uchar)0x00+0x33);
        }
        else if(ui->listWidget_2->currentRow()>=7)
        {
            if(ui->listWidget_4->currentRow()<=5)
            {
                sendData.append(ui->listWidget_4->currentRow()+0x33);
            }
            else if(ui->listWidget_4->currentRow()==0x06)
            {
                sendData.append(0x0a+0x33);
            }
        }
    }
    else if(ui->listWidget->currentRow()==0x04)
    {
        if(ui->listWidget_3->currentRow()==0x00)
            sendData.append(ui->listWidget_4->currentRow()+1+0x33);
        else if(ui->listWidget_3->currentRow()==0x01)
            sendData.append(0x03+0x33);
    }
    else if(ui->listWidget->currentRow()==0x05)
    {
        if(ui->listWidget_2->currentRow()==0x00)
        {
            if(ui->listWidget_4->currentRow()<=59)
            {
                sendData.append(ui->listWidget_4->currentRow()+1+0x33);
            }
            else
            {
                sendData.append((uchar)(0xff+0x33));
            }
        }
        else if(ui->listWidget_2->currentRow()==0x01)
        {
            if(ui->listWidget_4->currentRow()<=2)
            {
                sendData.append(ui->listWidget_4->currentRow()+1+0x33);
            }
            else
            {
                sendData.append((uchar)(0xff+0x33));
            }
        }
        else if(ui->listWidget_2->currentRow()==0x02||ui->listWidget_2->currentRow()==0x03||ui->listWidget_2->currentRow()==0x05||ui->listWidget_2->currentRow()==0x07)
        {
            if(ui->listWidget_4->currentRow()<=1)
            {
                sendData.append(ui->listWidget_4->currentRow()+1+0x33);
            }
            else
            {
                sendData.append((uchar)(0xff+0x33));
            }
        }
        else if(ui->listWidget_2->currentRow()==0x04)
        {
            if(ui->listWidget_4->currentRow()<=253)
            {
                sendData.append(ui->listWidget_4->currentRow()+1+0x33);
            }
            else
            {
                sendData.append((uchar)(0xff+0x33));
            }
        }
        else if(ui->listWidget_2->currentRow()==0x06)
        {
            if(ui->listWidget_4->currentRow()<=61)
            {
                sendData.append(ui->listWidget_4->currentRow()+1+0x33);
            }
            else
            {
                sendData.append((uchar)(0xff+0x33));
            }
        }
    }
}
//d1
void MainWindow::GetByteArray3(QByteArray &sendData)
{
    if(ui->listWidget->currentRow()==0)
    {
        if(ui->listWidget_3->currentRow()==5)
        {
            sendData.append((uchar)(0xff+0x33));
        }
        else
            sendData.append(ui->listWidget_3->currentRow()+0x33);
    }
    else if(ui->listWidget->currentRow()==0x02)
    {
        if(ui->listWidget_2->currentRow()<=1)
        {
            if(ui->listWidget_3->currentRow()<=2)
                sendData.append(ui->listWidget_3->currentRow()+1+0x33);
            else if(ui->listWidget_3->currentRow()==0x03)
            {
                sendData.append((uchar)(0xff+0x33));
            }
        }
        else if(ui->listWidget_2->currentRow()>=2&&ui->listWidget_2->currentRow()<=5)
        {
            if(ui->listWidget_3->currentRow()<=3)
            {
                sendData.append(ui->listWidget_3->currentRow()+0x33);
            }
            else if(ui->listWidget_3->currentRow()==0x04)
            {
                sendData.append((uchar)(0xff+0x33));
            }
        }
        else if(ui->listWidget_2->currentRow()==0x06)
        {
            if(ui->listWidget_3->currentRow()<=2)
            {
                sendData.append(ui->listWidget_3->currentRow()+1+0x33);
            }
            else if(ui->listWidget_3->currentRow()==3)
            {
                sendData.append((uchar)(0xff+0x33));
            }

        }
        else if(ui->listWidget_2->currentRow()==0x07)
        {
            sendData.append((uchar)0x00+0x33);
        }
    }
    else if(ui->listWidget->currentRow()==0x04)
    {
        if(ui->listWidget_3->currentRow()==0x00)
        {
            sendData.append(0x04+0x33);
        }
        else if(ui->listWidget_3->currentRow()==0x01)
        {
            sendData.append(0x12+0x33);
        }
    }
    else if(ui->listWidget->currentRow()==0x05)
    {
        if(ui->listWidget_2->currentRow()==0x04)
        {
            if(ui->listWidget_3->currentRow()==0x03)
            {
                sendData.append((uchar)(0xff+0x33));
            }
            else
                sendData.append(ui->listWidget_3->currentRow()+0x33);
        }
        else
        {
            if(ui->listWidget_3->currentRow()==0x0b)
            {
                sendData.append((uchar)(0x10+0x33));
            }
            else if(ui->listWidget_3->currentRow()==0x0c)
            {
                sendData.append((uchar)(0xff+0x33));
            }
            else
                sendData.append(ui->listWidget_3->currentRow()+0x33);
        }
    }
}
//d2
void MainWindow::GetByteArray2(QByteArray &sendData)
{
    if(ui->listWidget->currentRow()==0)
    {
        if(ui->listWidget_2->currentRow()<=10)
        {
            sendData.append(ui->listWidget_2->currentRow()+0x33);
        }

        if(ui->listWidget_2->currentRow()>=12&&ui->listWidget_2->currentRow()<=19)
        {
            sendData.append(ui->listWidget_2->currentRow()+0x09+0x33);
        }

        if(ui->listWidget_2->currentRow()>=21&&ui->listWidget_2->currentRow()<=28)
        {
            sendData.append(ui->listWidget_2->currentRow()+20+0x33);
        }

        if(ui->listWidget_2->currentRow()>=30&&ui->listWidget_2->currentRow()<=37)
        {
            sendData.append(ui->listWidget_2->currentRow()+31+0x33);
        }
    }
    else if(ui->listWidget->currentRow()==0x02)
    {
        if(ui->listWidget_2->currentRow()<=0x06)
        {
            sendData.append(ui->listWidget_2->currentRow()+1+0x33);
        }
        else if(ui->listWidget_2->currentRow()==0x07)
        {
            sendData.append((uchar)(0x80+0x33));
        }

    }
    else if(ui->listWidget->currentRow()==0x04)
    {
        if(ui->listWidget_2->currentRow()==0x00)
        {
            sendData.append(0x00+0x33);
        }
    }
    else if(ui->listWidget->currentRow()==0x05)
    {
        sendData.append(ui->listWidget_2->currentRow()+0x33);
    }
}
//D3
void MainWindow::GetByteArray1(QByteArray &sendData)
{

    sendData.append(ui->listWidget->currentRow()+0x33);
}

void MainWindow::AddCheckSum(QByteArray &sendData)
{
    unsigned char checkSum=0;
    for(int i=0;i<=sendData.length()-1;i++)
    {
        checkSum=checkSum+(uchar)sendData.data()[i];
    }
    sendData.append(checkSum);
    sendData.append(0x16);
}

void MainWindow::ReadData(QByteArray & readData,int i)
{
    readData.clear();
    QDateTime start=QDateTime::currentDateTime();
    while (start.msecsTo(QDateTime::currentDateTime())<3000)
    {
        QApplication::processEvents();
        if(dlt645[i].readyRead.count()>=1)
        {
            dlt645[i].vectorLocker.lock();
            dlt645[i].readyRead.pop_front();
            dlt645[i].vectorLocker.unlock();

            QByteArray data=dlt645[i].port.readAll();
            readData.append(data);
        }
        if(readData.length()>0)
            if(readData.data()[readData.length()-1]==0x16)
                break;
    }
}

void MainWindow::ParseRecvData(QByteArray recvData)
{
    if(recvData.data()[0]!=0x68)
        return;
    QByteArray data;
    data.clear();
    data.append(recvData[1]);
    data.prepend(recvData.data()[2]);
    data.prepend(recvData.data()[3]);
    data.prepend(recvData.data()[4]);
    data.prepend(recvData.data()[5]);
    data.prepend(recvData.data()[6]);
    qDebug()<<data.toHex();
    qDebug()<<__FUNCTION__<<__LINE__<<(uchar)recvData.data()[7];
    if((uchar)recvData.data()[7]!=0x68)
        return;
    qDebug()<<__FUNCTION__<<__LINE__;
    if((uchar)recvData.data()[8]!=0x91&&(uchar)recvData.data()[8]!=0xb1)
        return;
    qDebug()<<__FUNCTION__<<__LINE__;
    int dataLength=recvData.data()[9];
    qDebug()<<dataLength;
    if(recvData.data()[13]-0x33==0x00)
    {
        if(dataLength==8)
        {
            QByteArray data;
            data.clear();
            data.append(recvData.data()[9+5]-0x33);
            QString showvalue=data.toHex();
            showvalue.prepend(".");
            data.clear();
            data.append(recvData.data()[9+6]-0x33);
            showvalue.prepend(data.toHex());

            data.clear();
            data.append(recvData.data()[9+7]-0x33);
            showvalue.prepend(data.toHex());

            data.clear();
            data.append(recvData.data()[9+8]-0x33);
            showvalue.prepend(data.toHex());

            float value=showvalue.toFloat();
            QString units="kWh";
            if(recvData.data()[12]-0x33==(0x09)||recvData.data()[12]-0x33==0x0a)
                units="KVAh";
            //if()
            qDebug()<<value;
            ui->textEdit->setText(QString::number(value,'f',2)+units);
        }
        else if(dataLength==24)
        {
            ui->textEdit->clear();
            for(int i=0;i<=4;i++)
            {
                QByteArray data;
                data.clear();
                data.append(recvData.data()[9+5+4*i]-0x33);
                QString showvalue=data.toHex();
                showvalue.prepend(".");
                data.clear();
                data.append(recvData.data()[9+6+4*i]-0x33);
                showvalue.prepend(data.toHex());

                data.clear();
                data.append(recvData.data()[9+7+4*i]-0x33);
                showvalue.prepend(data.toHex());

                data.clear();
                data.append(recvData.data()[9+8+4*i]-0x33);
                showvalue.prepend(data.toHex());

                float value=showvalue.toFloat();
                qDebug()<<value;
                ui->textEdit->append(QString::number(value,'f',2)+"kWh");
            }
        }
    }
    else if(recvData.data()[13]-0x33==0x02)
    {
        qDebug()<<"变量数据标识"<<recvData.data()[12]-0x33<<dataLength;
        //D2=0x01;
        if(recvData.data()[12]-0x33==0x01&&dataLength==6)
        {
            ParseDetail(recvData,14,2,1,"V",3,1);
        }
        else if(recvData.data()[12]-0x33==0x01&&dataLength==10)
        {
            ParseDetail(recvData,14,2,3,"V",3,1);
        }
        else if(recvData.data()[12]-0x33==0x02&&dataLength==7)
        {
            ParseDetail(recvData,14,3,1,"A",3,3);
        }
        else if(recvData.data()[12]-0x33==0x02&&dataLength==13)
        {
            ParseDetail(recvData,14,3,3,"A",3,3);
        }
        else if((recvData.data()[12]-0x33==0x03||recvData.data()[12]-0x33==0x04||recvData.data()[12]-0x33==0x05)&&dataLength==7)
        {
            ParseDetail(recvData,14,3,1,"kW",2,4);
        }
        else if((recvData.data()[12]-0x33==0x03||recvData.data()[12]-0x33==0x04||recvData.data()[12]-0x33==0x05)&&dataLength==16)
        {
            ParseDetail(recvData,14,3,4,"kW",2,4);
        }
        else if((recvData.data()[12]-0x33==0x06)&&(dataLength==6))
        {
            ParseDetail(recvData,14,2,1,"分",1,3);
        }
        else if((recvData.data()[12]-0x33==0x06)&&(dataLength==12))
        {
            ParseDetail(recvData,14,2,4,"分",1,3);
        }
        else if((recvData.data()[12]-0x33==0x07)&&(dataLength==6))
        {

            ParseDetail(recvData,14,2,1,"°",3,1);
            qDebug()<<"相角";
        }
        else if((recvData.data()[12]-0x33==0x07)&&(dataLength==10))
        {
            ParseDetail(recvData,14,2,3,"°",3,1);
            qDebug()<<"相角";
        }
        else if(((uchar)(recvData.data()[12]-0x33)==0x80))
        {
            if(recvData.data()[10]-0x33==0x00)
            {
                ParseDetail(recvData,14,2,1,"V",3,1);
            }
            else if(recvData.data()[10]-0x33==0x01)
            {
                ParseDetail(recvData,14,3,1,"A",3,3);
            }
            else if(recvData.data()[10]-0x33==0x02)
            {
                ParseDetail(recvData,14,2,1,"Hz",2,2);
            }
            else if(recvData.data()[10]-0x33==0x03)
            {
                ParseDetail(recvData,14,3,1,"kW",2,4);
            }
            else if(recvData.data()[10]-0x33==0x04)
            {
                ParseDetail(recvData,14,3,1,"kW",2,4);
            }
            else if(recvData.data()[10]-0x33==0x05)
            {
                ParseDetail(recvData,14,3,1,"kvar",2,4);
            }
            else if(recvData.data()[10]-0x33==0x0a)
            {
                QString showValue="";
                QByteArray data;
                data.clear();
                data.append(recvData.data()[14]-0x33);
                showValue.append(data.toHex());
                data.clear();
                data.append(recvData.data()[15]-0x33);
                showValue.prepend(data.toHex());
                data.clear();
                data.append(recvData.data()[16]-0x33);
                showValue.prepend(data.toHex());
                data.clear();
                data.append(recvData.data()[17]-0x33);
                showValue.prepend(data.toHex());
                long value=showValue.toLong();
                ui->textEdit->setText(QString::number(value));
            }
        }
    }
}

void MainWindow::ParseRecvData(QByteArray recvData, int portID,int fourLoop)

{
    if(recvData.data()[0]!=0x68)
        return;
    QByteArray data;
    data.clear();
    data.append(recvData[1]);
    data.prepend(recvData.data()[2]);
    data.prepend(recvData.data()[3]);
    data.prepend(recvData.data()[4]);
    data.prepend(recvData.data()[5]);
    data.prepend(recvData.data()[6]);
    qDebug()<<data.toHex();
    qDebug()<<__FUNCTION__<<__LINE__<<(uchar)recvData.data()[7];
    if((uchar)recvData.data()[7]!=0x68)
        return;
    qDebug()<<__FUNCTION__<<__LINE__;
    if((uchar)recvData.data()[8]!=0x91&&(uchar)recvData.data()[8]!=0xb1)
        return;
    qDebug()<<__FUNCTION__<<__LINE__;
    int dataLength=recvData.data()[9];
    qDebug()<<__FUNCTION__<<__LINE__<<dataLength<<recvData.data()[13]-0x33;



    if(recvData.data()[13]-0x33==0x00)
    {
        if(dataLength==8)
        {
            QByteArray data;
            data.clear();
            data.append(recvData.data()[9+5]-0x33);
            QString showvalue=data.toHex();
            showvalue.prepend(".");
            data.clear();
            data.append(recvData.data()[9+6]-0x33);
            showvalue.prepend(data.toHex());

            data.clear();
            data.append(recvData.data()[9+7]-0x33);
            showvalue.prepend(data.toHex());

            data.clear();
            data.append(recvData.data()[9+8]-0x33);
            showvalue.prepend(data.toHex());

            float value=showvalue.toFloat();
            QString units="kWh";
            if(recvData.data()[12]-0x33==(0x09)||recvData.data()[12]-0x33==0x0a)
                units="KVAh";
            //if()
            qDebug()<<value;
            if(portID==0&&last8==true)
            {
                last8=false;
                ui->textEdit->clear();
            }
            ui->textEdit->append(QString("串口%0回路%1:").arg(portID).arg(fourLoop)+QString::number(value,'f',2)+units);
        }
        else if(dataLength==24)
        {
            for(int i=0;i<=4;i++)
            {
                QByteArray data;
                data.clear();
                data.append(recvData.data()[9+5+4*i]-0x33);
                QString showvalue=data.toHex();
                showvalue.prepend(".");
                data.clear();
                data.append(recvData.data()[9+6+4*i]-0x33);
                showvalue.prepend(data.toHex());

                data.clear();
                data.append(recvData.data()[9+7+4*i]-0x33);
                showvalue.prepend(data.toHex());

                data.clear();
                data.append(recvData.data()[9+8+4*i]-0x33);
                showvalue.prepend(data.toHex());

                float value=showvalue.toFloat();
                qDebug()<<value;
                if(portID==0&&last8==true)
                {
                    last8=false;
                    ui->textEdit->clear();
                }
                ui->textEdit->append(QString("串口%0回路%1:").arg(portID).arg(fourLoop)+QString::number(value,'f',2)+"kWh");
            }
        }
    }
    else if(recvData.data()[13]-0x33==0x02)
    {
        qDebug()<<"变量数据标识"<<recvData.data()[12]-0x33<<dataLength;
        //D2=0x01;
        if(recvData.data()[12]-0x33==0x01&&dataLength==6)
        {
            ParseDetail(recvData,14,2,1,"V",3,1,portID,fourLoop);
        }
        else if(recvData.data()[12]-0x33==0x01&&dataLength==10)
        {
            ParseDetail(recvData,14,2,3,"V",3,1,portID,fourLoop);
        }
        else if(recvData.data()[12]-0x33==0x02&&dataLength==7)
        {
            ParseDetail(recvData,14,3,1,"A",3,3,portID,fourLoop);
        }
        else if(recvData.data()[12]-0x33==0x02&&dataLength==13)
        {
            ParseDetail(recvData,14,3,3,"A",3,3,portID,fourLoop);
        }
        else if((recvData.data()[12]-0x33==0x03||recvData.data()[12]-0x33==0x04||recvData.data()[12]-0x33==0x05)&&dataLength==7)
        {
            ParseDetail(recvData,14,3,1,"kW",2,4,portID,fourLoop);
        }
        else if((recvData.data()[12]-0x33==0x03||recvData.data()[12]-0x33==0x04||recvData.data()[12]-0x33==0x05)&&dataLength==16)
        {
            ParseDetail(recvData,14,3,4,"kW",2,4,portID,fourLoop);
        }
        else if((recvData.data()[12]-0x33==0x06)&&(dataLength==6))
        {
            ParseDetail(recvData,14,2,1,"分",1,3,portID,fourLoop);
        }
        else if((recvData.data()[12]-0x33==0x06)&&(dataLength==12))
        {
            ParseDetail(recvData,14,2,4,"分",1,3,portID,fourLoop);
        }
        else if((recvData.data()[12]-0x33==0x07)&&(dataLength==6))
        {

            ParseDetail(recvData,14,2,1,"°",3,1,portID,fourLoop);
            qDebug()<<"相角";
        }
        else if((recvData.data()[12]-0x33==0x07)&&(dataLength==10))
        {
            ParseDetail(recvData,14,2,3,"°",3,1,portID,fourLoop);
            qDebug()<<"相角";
        }
        else if(((uchar)(recvData.data()[12]-0x33)==0x80))
        {
            if(recvData.data()[10]-0x33==0x00)
            {
                ParseDetail(recvData,14,2,1,"V",3,1,portID,fourLoop);
            }
            else if(recvData.data()[10]-0x33==0x01)
            {
                ParseDetail(recvData,14,3,1,"A",3,3,portID,fourLoop);
            }
            else if(recvData.data()[10]-0x33==0x02)
            {
                ParseDetail(recvData,14,2,1,"Hz",2,2,portID,fourLoop);
            }
            else if(recvData.data()[10]-0x33==0x03)
            {
                ParseDetail(recvData,14,3,1,"kW",2,4,portID,fourLoop);
            }
            else if(recvData.data()[10]-0x33==0x04)
            {
                ParseDetail(recvData,14,3,1,"kW",2,4,portID,fourLoop);
            }
            else if(recvData.data()[10]-0x33==0x05)
            {
                ParseDetail(recvData,14,3,1,"kvar",2,4,portID,fourLoop);
            }
            else if(recvData.data()[10]-0x33==0x0a)
            {
                QString showValue="";
                QByteArray data;
                data.clear();
                data.append(recvData.data()[14]-0x33);
                showValue.append(data.toHex());
                data.clear();
                data.append(recvData.data()[15]-0x33);
                showValue.prepend(data.toHex());
                data.clear();
                data.append(recvData.data()[16]-0x33);
                showValue.prepend(data.toHex());
                data.clear();
                data.append(recvData.data()[17]-0x33);
                showValue.prepend(data.toHex());
                long value=showValue.toLong();
                if(portID==0&&last8==true)
                {
                    last8=false;
                    ui->textEdit->clear();
                }
                ui->textEdit->append(QString("串口%0回路%1:").arg(portID).arg(fourLoop)+QString::number(value));
            }
        }
    }
    else if(recvData.data()[13]-0x33==0x04)
    {
        qDebug()<<"收到参数数据包";
        ParseParameterPackage(recvData);
    }
    else if(recvData.data()[13]-0x33==0x05)
    {
        ParseFreezePackage(recvData);
    }
}

void MainWindow::ParseParameterPackage(QByteArray recvData)
{
    uchar DI0=recvData.data()[10]-0x33;
    uchar DI1=recvData.data()[11]-0x33;
    QByteArray tmp;
    tmp=recvData;

    if(DI1==0x04)
    {
        if(DI0==1)//通信地址
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(6,2);
            for(int i=0;i<=5;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            QByteArray tempArray2;
            tempArray2.clear();
            tempArray2.resize(6);
            for(int i=0;i<=tmp.length()-1;i++)
            {
                tempArray2.data()[i]=tmp[5-i];
            }
            ui->textEdit->append(tempArray2.toHex());
        }
        else if(DI0==2)//表号
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(6,2);
            for(int i=0;i<=5;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            QByteArray tempArray2;
            tempArray2.clear();
            tempArray2.resize(6);
            for(int i=0;i<=tmp.length()-1;i++)
            {
                tempArray2.data()[i]=tmp[5-i];
            }
            ui->textEdit->append(tempArray2.toHex());
        }
        else if(DI0==3)//资产管理号
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(32,2);
            for(int i=0;i<=31;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            QByteArray tempArray2;
            tempArray2.clear();
            tempArray2.resize(32);
            for(int i=0;i<=tmp.length()-1;i++)
            {
                tempArray2.data()[i]=tmp[31-i];
            }
            ui->textEdit->append(tempArray2.toHex());
        }
        else if(DI0==0x04||DI0==0x05||DI0==0x06)
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(6,2);
            for(int i=0;i<=5;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            ui->textEdit->append(tmp.data());
        }
        else if(DI0==0x07||DI0==0x08)
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(4,2);
            for(int i=0;i<=3;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            ui->textEdit->append(tmp.data());
        }
        else if(DI0==0x09||DI0==0x0a)
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(3,2);
            for(int i=0;i<=2;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            QByteArray tempArray2;
            tempArray2.clear();
            tempArray2.resize(3);
            for(int i=0;i<=tmp.length()-1;i++)
            {
                tempArray2.data()[i]=tmp[2-i];
            }
            ui->textEdit->append(tempArray2.toHex());
        }
        else if(DI0==0x0B||DI0==0x0c)
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(10,2);
            for(int i=0;i<=9;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            ui->textEdit->append(tmp.data());
            qDebug()<<"----------------->";
        }
        else if(DI0==0x0d)
        {
            tmp=tmp.remove(0,14);
            tmp=tmp.remove(16,2);
            for(int i=0;i<=15;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            ui->textEdit->append(tmp.data());
            qDebug()<<"----------------->";
        }
        else if(DI0==0x0e)
        {

            tmp=tmp.remove(0,14);
            tmp=tmp.remove(6,2);
            for(int i=0;i<=5;i++)
            {
                tmp.data()[i]=tmp.data()[i]-0x33;
            }

            QByteArray tempArray2;
            tempArray2.clear();
            tempArray2.resize(6);
            for(int i=0;i<=tmp.length()-1;i++)
            {
                tempArray2.data()[i]=tmp[2-i];
            }
            ui->textEdit->append(tempArray2.toHex());
        }
    }
    else if(DI1==0x12)
    {
        if(DI0==0x03)
        {
            QByteArray tmp;
            tmp.resize(2);
            tmp.data()[0]=recvData.data()[15]-0x33;
            tmp.data()[1]=recvData.data()[14]-0x33;
            QString showStr;
            showStr.clear();
            showStr=tmp.toHex(':');
            ui->textEdit->append(showStr);
        }
    }
}

void MainWindow::ParseFreezePackage(QByteArray recvData)
{
    bool hasHouXuData=false;
    if((uchar)recvData.data()[8]==0x91)
    {
        hasHouXuData=false;
    }
    else if((uchar)recvData.data()[8]==0xb1)
    {
        hasHouXuData=true;
    }

    uchar D0,D1,D2,D3;
    D0=recvData.data()[10]-0x33;
    D1=recvData.data()[11]-0x33;
    D2=recvData.data()[12]-0x33;
    D3=recvData.data()[13]-0x33;
    qDebug()<<"D0"<<D0<<"D1"<<D1;
    if(D2==0x04)
    {

    }
    else
    {
        if(D1==0x00)
        {
            qDebug()<<"recv length is "<<recvData.length();
            if(recvData.length()>=21)
            {
                qDebug()<<"recv length is enough";
                QByteArray temp;
                temp.resize(1);
                temp.data()[0]=(uchar)recvData.data()[18]-0x33;
                QString showStr;
                showStr+=temp.toHex();
                showStr+="-";

                temp.data()[0]=(uchar)recvData.data()[17]-0x33;
                showStr+=temp.toHex();
                showStr+="-";

                temp.data()[0]=(uchar)recvData.data()[16]-0x33;
                showStr+=temp.toHex();
                showStr+=" ";

                temp.data()[0]=(uchar)recvData.data()[15]-0x33;
                showStr+=temp.toHex();
                showStr+=":";

                temp.data()[0]=(uchar)recvData.data()[14]-0x33;
                showStr+=temp.toHex();
                ui->textEdit->setText(showStr);
            }
        }
        if(D1>=0x01&&D1<=0x08)
        {
            QString unit;//单位
            if(D1>=01&&D1<=02)
                unit="kWh";
            else if(D1>=3&&D1<=8)
                unit="kvarh";


            QString showValue;
            showValue.clear();
            QByteArray temp;
            temp.resize(4);
            //第1个数
            temp.data()[0]=recvData.data()[17]-0x33;
            temp.data()[1]=recvData.data()[16]-0x33;
            temp.data()[2]=recvData.data()[15]-0x33;
            temp.data()[3]=recvData.data()[14]-0x33;
            showValue=temp.toHex();
            showValue.insert(6,'.');
            ui->textEdit->append("总电能:"+QString::number(showValue.toFloat())+unit);
            //第2个数
            temp.data()[0]=recvData.data()[21]-0x33;
            temp.data()[1]=recvData.data()[20]-0x33;
            temp.data()[2]=recvData.data()[19]-0x33;
            temp.data()[3]=recvData.data()[18]-0x33;
            showValue=temp.toHex();
            showValue.insert(6,'.');
            ui->textEdit->append("费率1:"+QString::number(showValue.toFloat())+unit);
            //第3个数
            temp.data()[0]=recvData.data()[25]-0x33;
            temp.data()[1]=recvData.data()[24]-0x33;
            temp.data()[2]=recvData.data()[23]-0x33;
            temp.data()[3]=recvData.data()[22]-0x33;
            showValue=temp.toHex();
            showValue.insert(6,'.');
            ui->textEdit->append("费率2:"+QString::number(showValue.toFloat())+unit);
            //第4个数
            temp.data()[0]=recvData.data()[29]-0x33;
            temp.data()[1]=recvData.data()[28]-0x33;
            temp.data()[2]=recvData.data()[27]-0x33;
            temp.data()[3]=recvData.data()[26]-0x33;
            showValue=temp.toHex();
            showValue.insert(6,'.');
            ui->textEdit->append("费率3:"+QString::number(showValue.toFloat())+unit);
            //第5个数
            temp.data()[0]=recvData.data()[33]-0x33;
            temp.data()[1]=recvData.data()[32]-0x33;
            temp.data()[2]=recvData.data()[31]-0x33;
            temp.data()[3]=recvData.data()[30]-0x33;
            showValue=temp.toHex();
            showValue.insert(6,'.');
            ui->textEdit->append("费率4:"+QString::number(showValue.toFloat())+unit);
        }
        if(D1>=0x09&&D1<=0x0A)
        {
            //有功总
            QByteArray temp;
            temp.clear();
            temp.resize(3);
            temp.data()[0]=recvData.data()[16]-0x33;
            temp.data()[1]=recvData.data()[15]-0x33;
            temp.data()[2]=recvData.data()[14]-0x33;
            QString showValue=temp.toHex();
            showValue.insert(2,'.');
            showValue=QString::number(showValue.toFloat());
            showValue="有功总:"+showValue+"kW ";

            temp.clear();
            temp.resize(1);
            temp.data()[0]=recvData.data()[21]-0x33;
            QString tempStr=temp.toHex();
            tempStr+="年";
            showValue=showValue+tempStr;
            temp.data()[0]=recvData.data()[20]-0x33;
            tempStr=temp.toHex();
            tempStr+="月";
            showValue+=tempStr;
            temp.data()[0]=recvData.data()[19]-0x33;
            tempStr=temp.toHex();
            tempStr+="日";
            showValue+=(tempStr+" ");

            temp.data()[0]=recvData.data()[18]-0x33;
            tempStr=temp.toHex();
            tempStr+="时";
            showValue+=(tempStr);

            temp.data()[0]=recvData.data()[17]-0x33;
            tempStr=temp.toHex();
            tempStr+="分";
            showValue+=(tempStr);
            ui->textEdit->append(showValue);
            //费率1
            showValue.clear();
            temp.clear();
            temp.resize(3);
            temp.data()[0]=recvData.data()[24]-0x33;
            temp.data()[1]=recvData.data()[23]-0x33;
            temp.data()[2]=recvData.data()[22]-0x33;
            showValue=temp.toHex();
            showValue.insert(2,'.');
            showValue=QString::number(showValue.toFloat());
            showValue="费率1:"+showValue+"kW ";

            temp.clear();
            temp.resize(1);
            temp.data()[0]=recvData.data()[29]-0x33;
            tempStr=temp.toHex();
            tempStr+="年";
            showValue=showValue+tempStr;
            temp.data()[0]=recvData.data()[28]-0x33;
            tempStr=temp.toHex();
            tempStr+="月";
            showValue+=tempStr;
            temp.data()[0]=recvData.data()[27]-0x33;
            tempStr=temp.toHex();
            tempStr+="日";
            showValue+=(tempStr+" ");

            temp.data()[0]=recvData.data()[26]-0x33;
            tempStr=temp.toHex();
            tempStr+="时";
            showValue+=(tempStr);

            temp.data()[0]=recvData.data()[25]-0x33;
            tempStr=temp.toHex();
            tempStr+="分";
            showValue+=(tempStr);
            ui->textEdit->append(showValue);

            //费率2
            showValue.clear();
            temp.clear();
            temp.resize(3);
            temp.data()[0]=recvData.data()[24+8]-0x33;
            temp.data()[1]=recvData.data()[23+8]-0x33;
            temp.data()[2]=recvData.data()[22+8]-0x33;
            showValue=temp.toHex();
            showValue.insert(2,'.');
            showValue=QString::number(showValue.toFloat());
            showValue="费率2:"+showValue+"kW ";

            temp.clear();
            temp.resize(1);
            temp.data()[0]=recvData.data()[29+8]-0x33;
            tempStr=temp.toHex();
            tempStr+="年";
            showValue=showValue+tempStr;
            temp.data()[0]=recvData.data()[28+8]-0x33;
            tempStr=temp.toHex();
            tempStr+="月";
            showValue+=tempStr;
            temp.data()[0]=recvData.data()[27+8]-0x33;
            tempStr=temp.toHex();
            tempStr+="日";
            showValue+=(tempStr+" ");

            temp.data()[0]=recvData.data()[26+8]-0x33;
            tempStr=temp.toHex();
            tempStr+="时";
            showValue+=(tempStr);

            temp.data()[0]=recvData.data()[25+8]-0x33;
            tempStr=temp.toHex();
            tempStr+="分";
            showValue+=(tempStr);
            ui->textEdit->append(showValue);
            //费率3
            showValue.clear();
            temp.clear();
            temp.resize(3);
            temp.data()[0]=recvData.data()[24+16]-0x33;
            temp.data()[1]=recvData.data()[23+16]-0x33;
            temp.data()[2]=recvData.data()[22+16]-0x33;
            showValue=temp.toHex();
            showValue.insert(2,'.');
            showValue=QString::number(showValue.toFloat());
            showValue="费率3:"+showValue+"kW ";

            temp.clear();
            temp.resize(1);
            temp.data()[0]=recvData.data()[29+16]-0x33;
            tempStr=temp.toHex();
            tempStr+="年";
            showValue=showValue+tempStr;
            temp.data()[0]=recvData.data()[28+16]-0x33;
            tempStr=temp.toHex();
            tempStr+="月";
            showValue+=tempStr;
            temp.data()[0]=recvData.data()[27+16]-0x33;
            tempStr=temp.toHex();
            tempStr+="日";
            showValue+=(tempStr+" ");

            temp.data()[0]=recvData.data()[26+16]-0x33;
            tempStr=temp.toHex();
            tempStr+="时";
            showValue+=(tempStr);

            temp.data()[0]=recvData.data()[25+16]-0x33;
            tempStr=temp.toHex();
            tempStr+="分";
            showValue+=(tempStr);
            ui->textEdit->append(showValue);

            //费率4
            showValue.clear();
            temp.clear();
            temp.resize(3);
            temp.data()[0]=recvData.data()[24+24]-0x33;
            temp.data()[1]=recvData.data()[23+24]-0x33;
            temp.data()[2]=recvData.data()[22+24]-0x33;
            showValue=temp.toHex();
            showValue.insert(2,'.');
            showValue=QString::number(showValue.toFloat());
            showValue="费率4:"+showValue+"kW ";

            temp.clear();
            temp.resize(1);
            temp.data()[0]=recvData.data()[29+24]-0x33;
            tempStr=temp.toHex();
            tempStr+="年";
            showValue=showValue+tempStr;
            temp.data()[0]=recvData.data()[28+24]-0x33;
            tempStr=temp.toHex();
            tempStr+="月";
            showValue+=tempStr;
            temp.data()[0]=recvData.data()[27+24]-0x33;
            tempStr=temp.toHex();
            tempStr+="日";
            showValue+=(tempStr+" ");

            temp.data()[0]=recvData.data()[26+24]-0x33;
            tempStr=temp.toHex();
            tempStr+="时";
            showValue+=(tempStr);

            temp.data()[0]=recvData.data()[25+24]-0x33;
            tempStr=temp.toHex();
            tempStr+="分";
            showValue+=(tempStr);
            ui->textEdit->append(showValue);
        }
        if(D1==0x10)
        {
            //总有功功率
            for(int i=0;i<=7;i++)
            {
                QString tiltle,unit;
                if(i==0)
                {
                    tiltle="总有功功率";
                    unit="kW";
                }
                else if(i==1)
                {
                    tiltle="A象有功功率";
                    unit="kW";
                }
                else if(i==2)
                {
                    tiltle="B象有功功率";
                    unit="kW";
                }
                else if(i==3)
                {
                    tiltle="C象有功功率";
                    unit="kW";
                }
                else if(i==4)
                {
                    tiltle="总无功功率";
                    unit="kvar";
                }
                else if(i==5)
                {
                    tiltle="A象无功功率";
                    unit="kvar";
                }
                else if(i==6)
                {
                    tiltle="B象无功功率";
                    unit="kvar";
                }
                else if(i==7)
                {
                    tiltle="C象无功功率";
                    unit="kvar";
                }

                QByteArray tmp;
                QString showValue,tmpStr;
                tmp.clear();
                showValue.clear();
                tmpStr.clear();

                tmp.resize(3);
                tmp.data()[0]=recvData.data()[16+3*i]-0x33;
                tmp.data()[1]=recvData.data()[15+3*i]-0x33;
                tmp.data()[2]=recvData.data()[14+3*i]-0x33;

                tmpStr=tmp.toHex();
                tmpStr.insert(2,'.');
                tmpStr=QString::number(tmpStr.toFloat());

                showValue=tiltle+tmpStr+unit;
                ui->textEdit->append(showValue);
            }
        }
        if(D1==0xff)
        {
            ui->textEdit->append(recvData.toHex());
        }
    }

}

void MainWindow::ParseDetail(QByteArray recvData, int start, int oneGroup, int gropNumber, QString unit, int decimal, int decimalPoint)
{
    QString showValue="";
    //    if(portid==0)
    //    {
    //        ui->textEdit->clear();
    //    }
    for(int j=0;j<gropNumber;j++)
    {
        showValue.clear();
        for(int i=0;i<=oneGroup-1;i++)
        {
            uchar dataVlue=recvData.data()[start+i+j*oneGroup]-0x33;
            if(i<oneGroup-1)
            {
                QByteArray data;
                data.resize(0);
                data.clear();
                data.append(dataVlue);
                showValue.prepend(data.toHex());

            }
            else if(i==oneGroup-1)
            {
                if((dataVlue&0x80)==0x80)
                {
                    dataVlue=dataVlue&0x7f;
                    QByteArray  data;
                    data.clear();
                    data.append(dataVlue);
                    showValue.prepend(data.toHex());
                    showValue.insert(decimal,".");
                    showValue.prepend("-");
                    float realValue=showValue.toFloat();
                    ui->textEdit->append(QString::number(realValue,'f',decimalPoint)+unit);
                }
                else
                {
                    QByteArray data;
                    data.clear();
                    data.append(dataVlue);
                    showValue.prepend(data.toHex());
                    showValue.insert(decimal,".");
                    float realValue=showValue.toFloat();
                    ui->textEdit->append(QString::number(realValue,'f',decimalPoint)+unit);
                }
            }
        }
    }
}

void MainWindow::ParseDetail(QByteArray recvData, int start, int oneGroup, int gropNumber, QString unit, int decimal, int decimalPoint, int portid,int fourLoop)
{
    QString showValue="";
    if(portid==0&&last8==true)
    {
        last8=false;
        ui->textEdit->clear();
    }
    for(int j=0;j<gropNumber;j++)
    {
        showValue.clear();
        for(int i=0;i<=oneGroup-1;i++)
        {
            uchar dataVlue=recvData.data()[start+i+j*oneGroup]-0x33;
            if(i<oneGroup-1)
            {
                QByteArray data;
                data.resize(0);
                data.clear();
                data.append(dataVlue);
                showValue.prepend(data.toHex());

            }
            else if(i==oneGroup-1)
            {
                if((dataVlue&0x80)==0x80)
                {
                    dataVlue=dataVlue&0x7f;
                    QByteArray  data;
                    data.clear();
                    data.append(dataVlue);
                    showValue.prepend(data.toHex());
                    showValue.insert(decimal,".");
                    showValue.prepend("-");
                    float realValue=showValue.toFloat();
                    ui->textEdit->append(QString("串口%0回路%1:").arg(portid).arg(fourLoop)+QString::number(realValue,'f',decimalPoint)+unit);
                }
                else
                {
                    QByteArray data;
                    data.clear();
                    data.append(dataVlue);
                    showValue.prepend(data.toHex());
                    showValue.insert(decimal,".");
                    float realValue=showValue.toFloat();
                    ui->textEdit->append(QString("串口%0回路%1:").arg(portid).arg(fourLoop)+QString::number(realValue,'f',decimalPoint)+unit);
                }
            }
        }
    }
}

void MainWindow::ParseDateData(QByteArray recvData)
{
    qDebug()<<"接收到的地址读取字节序:"<<recvData.toHex()<<"length="<<recvData.length();
    //判断接收到的字节数是不是18。读取地址的命令返回字节数是18。
    if(recvData.length()!=18)
    {
        return;
    }
    //判断头是不是0x68
    if((uchar)recvData.data()[0]!=0x68)
    {
        return;
    }
    //选取返回的字节数
    //获取buf
    QByteArray tempArray=recvData;
    tempArray.remove(0,10);
    tempArray.remove(6,tempArray.length()-6);

    qDebug()<<"截取的地址buf为:"<<tempArray.toHex();
    for(int i=0;i<=tempArray.length()-1;i++)
    {
        tempArray.data()[i]=tempArray.data()[i]-0x33;
    }

    QByteArray tempArray2;
    tempArray2.clear();
    tempArray2.resize(6);
    for(int i=0;i<=tempArray.length()-1;i++)
    {
        tempArray2.data()[i]=tempArray[5-i];
    }
    ui->lineEdit->setText(tempArray2.toHex());
}

void MainWindow::CheckBoxChecked()
{
    if(ui->checkBox->isChecked())
    {
        timer.start(ui->spinBox->value());
    }
    else
        timer.stop();
}
void MainWindow::ItemSelectChanged()
{
    qDebug()<<__FUNCTION__<<ui->listWidget_2->currentRow();
    if(ui->listWidget->currentRow()==0)
    {
        if(ui->listWidget_2->currentRow()>=12)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x00(总)");
            ui->listWidget_3->setCurrentRow(0);
        }
        else
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x00(有功总电能)");
            ui->listWidget_3->addItem("0x01(费率1电能)");
            ui->listWidget_3->addItem("0x02(费率2电能)");
            ui->listWidget_3->addItem("0x03(费率3电能)");
            ui->listWidget_3->addItem("0x04(费率4电能)");
            ui->listWidget_3->addItem("0xff(数据块)");
            ui->listWidget_3->setCurrentRow(0);
        }
    }
    else if(ui->listWidget->currentRow()==2)
    {
        if(ui->listWidget_2->currentRow()==0)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x01(A相电压)");
            ui->listWidget_3->addItem("0x02(B相电压)");
            ui->listWidget_3->addItem("0x03(C相电压)");
            ui->listWidget_3->addItem("0xff(电压数据块)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(总)");
            ui->listWidget_4->setCurrentRow(0);
        }
        else if(ui->listWidget_2->currentRow()==1)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x01(A相电流)");
            ui->listWidget_3->addItem("0x02(B相电流)");
            ui->listWidget_3->addItem("0x03(C相电流)");
            ui->listWidget_3->addItem("0xff(电流数据块)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(总)");
            ui->listWidget_4->setCurrentRow(0);
        }
        else if(ui->listWidget_2->currentRow()==2)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x00(瞬时总有功功率)");
            ui->listWidget_3->addItem("0x01(A相瞬时有功功率)");
            ui->listWidget_3->addItem("0x03(B相瞬时有功功率)");
            ui->listWidget_3->addItem("0x04(C相瞬时有功功率)");
            ui->listWidget_3->addItem("0xff(瞬时有功功率数据块)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(总)");
            ui->listWidget_4->setCurrentRow(0);
        }
        else if(ui->listWidget_2->currentRow()==3)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x00(瞬时总无功功率)");
            ui->listWidget_3->addItem("0x01(A相瞬时无功功率)");
            ui->listWidget_3->addItem("0x03(B相瞬时无功功率)");
            ui->listWidget_3->addItem("0x04(C相瞬时无功功率)");
            ui->listWidget_3->addItem("0xff(瞬时无功功率数据块)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(总)");
            ui->listWidget_4->setCurrentRow(0);
        }
        else if(ui->listWidget_2->currentRow()==4)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x00(瞬时总视在功率)");
            ui->listWidget_3->addItem("0x01(A相瞬时视在功率)");
            ui->listWidget_3->addItem("0x03(B相瞬时视在功率)");
            ui->listWidget_3->addItem("0x04(C相瞬时视在功率)");
            ui->listWidget_3->addItem("0xff(瞬时视在功率数据块)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(总)");
            ui->listWidget_4->setCurrentRow(0);
        }
        else if(ui->listWidget_2->currentRow()==5)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x00(总功率因数)");
            ui->listWidget_3->addItem("0x01(A相功率因数)");
            ui->listWidget_3->addItem("0x03(B相功率因数)");
            ui->listWidget_3->addItem("0x04(C相功率因数)");
            ui->listWidget_3->addItem("0xff(功率因数数据块)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(总)");
            ui->listWidget_4->setCurrentRow(0);
        }
        else if(ui->listWidget_2->currentRow()==6)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x01(A相相角)");
            ui->listWidget_3->addItem("0x02(B相相角)");
            ui->listWidget_3->addItem("0x03(C相相角)");
            ui->listWidget_3->addItem("0xff(相角数据块)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(总)");
            ui->listWidget_4->setCurrentRow(0);
        }
        else if(ui->listWidget_2->currentRow()==7)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("0x00(零线电流)");
            ui->listWidget_3->setCurrentRow(0);
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("0x00(零地电压)");
            ui->listWidget_4->addItem("0x01(零线电流)");
            ui->listWidget_4->addItem("0x02(电网频率)");
            ui->listWidget_4->addItem("0x03(一分钟内有功总平均功率)");
            ui->listWidget_4->addItem("0x04(当前有功需量)");
            ui->listWidget_4->addItem("0x05(当前无功需量)");
            ui->listWidget_4->addItem("0x0a(内部电池工作时间)");
            ui->listWidget_4->setCurrentRow(0);
        }
    }
    else if(ui->listWidget->currentRow()==0x04)
    {
    }
    else if(ui->listWidget->currentRow()==5)
    {
        if(ui->listWidget_2->currentRow()==0x04)
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("(0x00)冻结时间");
            ui->listWidget_3->addItem("(0x01)正向有功电量");
            ui->listWidget_3->addItem("(0x02)反向有功电量");
            ui->listWidget_3->addItem("(0xff)数据块");
        }
        else
        {
            ui->listWidget_3->clear();
            ui->listWidget_3->addItem("(0x00)冻结时间");
            ui->listWidget_3->addItem("(0x01)正向有功电量");
            ui->listWidget_3->addItem("(0x02)反向有功电量");
            ui->listWidget_3->addItem("(0x03)组合无功1电量");
            ui->listWidget_3->addItem("(0x04)组合无功2电量");
            ui->listWidget_3->addItem("(0x05)一象限无功电量");
            ui->listWidget_3->addItem("(0x06)二象限无功电量");
            ui->listWidget_3->addItem("(0x07)三象限无功电量");
            ui->listWidget_3->addItem("(0x08)四象限无功电量");
            ui->listWidget_3->addItem("(0x09)正象有功最大需量");
            ui->listWidget_3->addItem("(0x0a)反向有功最大需量");
            ui->listWidget_3->addItem("(0x10)有功无功功率");
            ui->listWidget_3->addItem("(0xff)数据块");
        }

        if(ui->listWidget_2->currentRow()==0)
        {
            ui->listWidget_4->clear();
            for(int i=1;i<=60;i++)
            {
                QByteArray arry;
                arry.resize(1);
                arry.data()[0]=i;
                QString temp=arry.toHex();
                QString itemStr=QString("(0x%0)上%1次").arg(temp).arg(i);
                ui->listWidget_4->addItem(itemStr);
            }
            ui->listWidget_4->addItem("数据块");
        }
        else if(ui->listWidget_2->currentRow()==0x04)
        {
            ui->listWidget_4->clear();
            for(int i=1;i<=254;i++)
            {
                QByteArray arry;
                arry.resize(1);
                arry.data()[0]=i;
                QString temp=arry.toHex();
                QString itemStr=QString("(0x%0)上%1次").arg(temp).arg(i);
                ui->listWidget_4->addItem(itemStr);
            }
            ui->listWidget_4->addItem("(0xff)数据块");
        }
        else if(ui->listWidget_2->currentRow()==0x06)
        {
            ui->listWidget_4->clear();
            for(int i=1;i<=62;i++)
            {
                QByteArray arry;
                arry.resize(1);
                arry.data()[0]=i;
                QString temp=arry.toHex();
                QString itemStr=QString("(0x%0)上%1次").arg(temp).arg(i);
                ui->listWidget_4->addItem(itemStr);
            }
            ui->listWidget_4->addItem("(0xff)数据块");
        }
        else if(ui->listWidget_2->currentRow()==0x01)
        {
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("(0x01)上1次");
            ui->listWidget_4->addItem("(0x02)上2次");
            ui->listWidget_4->addItem("(0x03)上3次");
            ui->listWidget_4->addItem("(0xff)数据块");
        }
        else if(ui->listWidget_2->currentRow()==0x02||ui->listWidget_2->currentRow()==0x03||ui->listWidget_2->currentRow()==0x05||ui->listWidget_2->currentRow()==0x07)
        {
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("(0x01)上1次");
            ui->listWidget_4->addItem("(0x02)上2次");
            ui->listWidget_4->addItem("(0xff)数据块");
        }

        ui->listWidget_3->setCurrentRow(0);
        ui->listWidget_4->setCurrentRow(0);
    }
}

void MainWindow::OpenPort()
{

    if(ui->pushButton->text()=="打开端口")
    {
        dlt645[0].SetPort(ui->comboBox->currentText(),ui->comboBox_2->currentText().toInt());
        int portCnt=0;
        int i=0;
        dlt645[i].port.open(QSerialPort::ReadWrite);
        if(!dlt645[i].port.isOpen())
        {
            QMessageBox a;
            a.setText(dlt645[i].port.portName()+"打开失败");
            a.show();
            a.exec();
        }
        else
        {
            QMessageBox a;
            a.setText("打开成功");
            a.show();
            a.exec();
        }
        ui->pushButton->setText("关闭端口");

    }
    else if(ui->pushButton->text()=="关闭端口")
    {

        int closeCnt=0;
        int i=0;
        {
            dlt645[i].port.close();
            if(dlt645[i].port.isOpen())
            {
                QMessageBox a;
                a.setText(dlt645[i].port.portName()+"关闭失败");
                a.show();
                a.exec();
            }
            else
            {
                closeCnt++;
                QMessageBox a;
                a.setText("关闭成功");
                a.show();
                a.exec();
                ui->pushButton->setText("打开端口");
            }
        }
    }
    qDebug()<<__FUNCTION__;
}

void MainWindow::SendReadData()
{
    qDebug()<<__FUNCTION__;
    ui->textEdit->clear();
    if(dlt645[0].port.isOpen())
    {

        QString fourLoop[4];
        fourLoop[0]=ui->lineEdit->text();

        QByteArray SendData;
        SendData.clear();
        SendData.append(0x68);
        QString adder=fourLoop[0];
        QString tmp[6];
        for(int k=0;k<=5;k++)
        {
            tmp[k]=adder.right(2);
            adder.remove(adder.length()-2,2);
            SendData.append(QByteArray::fromHex(tmp[k].toUtf8()));
            qDebug()<<"地址:"<<adder<<tmp[k];
        }

        SendData.append(0x68);
        SendData.append(0x11);
        SendData.append(0x04);
        GetByteArray4(SendData);
        GetByteArray3(SendData);
        GetByteArray2(SendData);
        GetByteArray1(SendData);
        AddCheckSum(SendData);
        qDebug()<<"send:"<<SendData.toHex();

        dlt645[0].port.write(SendData);
        dlt645[0].port.waitForBytesWritten();
        QByteArray recvData;
        recvData.clear();
        ReadData(recvData,0);
        qDebug()<<"recv:"<<recvData.toHex();
        ParseRecvData(recvData,0,0);

    }
    else
    {
        QMessageBox a;
        a.setText("端口未打开");
        a.show();
        a.exec();
    }
}

void MainWindow::ListWidget1ItemSelectChanged()
{
    if(ui->listWidget->currentRow()==1)
    {
        ui->listWidget_2->clear();
        ui->listWidget_3->clear();
        ui->listWidget_4->clear();
    }
    else if(ui->listWidget->currentRow()==0)
    {
        ui->listWidget_2->clear();
        ui->listWidget_2->addItem("0x00(组合有功总)");
        ui->listWidget_2->addItem("0x01(正向有功总)");
        ui->listWidget_2->addItem("0x02(反向有功总)");
        ui->listWidget_2->addItem("0x03(组合无功1总)");
        ui->listWidget_2->addItem("0x04(组合无功2总)");
        ui->listWidget_2->addItem("0x05(一象限无功总)");
        ui->listWidget_2->addItem("0x06(二象限无功总)");
        ui->listWidget_2->addItem("0x07(三象限无功总)");
        ui->listWidget_2->addItem("0x08(四象限无功总)");
        ui->listWidget_2->addItem("0x09(正向视在总)");
        ui->listWidget_2->addItem("0x0a(反向视在总)");
        ui->listWidget_2->addItem("");
        ui->listWidget_2->addItem("0x15(A相正向有功)");
        ui->listWidget_2->addItem("0x16(A相反向有功)");
        ui->listWidget_2->addItem("0x17(A相组合无功1)");
        ui->listWidget_2->addItem("0x18(A相组合无功2)");
        ui->listWidget_2->addItem("0x19(A相1象限无功)");
        ui->listWidget_2->addItem("0x1a(A相2象限无功)");
        ui->listWidget_2->addItem("0x1b(A相3象限无功)");
        ui->listWidget_2->addItem("0x1c(A相4象限无功)");
        ui->listWidget_2->addItem("");
        ui->listWidget_2->addItem("0x29(B相正向有功)");
        ui->listWidget_2->addItem("0x2a(B相反向有功)");
        ui->listWidget_2->addItem("0x2b(B相组合无功1)");
        ui->listWidget_2->addItem("0x2c(B相组合无功2)");
        ui->listWidget_2->addItem("0x2d(B相第一象限无功)");
        ui->listWidget_2->addItem("0x2e(B相第2象限无功)");
        ui->listWidget_2->addItem("0x2f(B相第3象限无功)");
        ui->listWidget_2->addItem("0x30(B相第4象限无功)");
        ui->listWidget_2->addItem("");
        ui->listWidget_2->addItem("0x3d(C相正向有功)");
        ui->listWidget_2->addItem("0x3e(C相反向有功)");
        ui->listWidget_2->addItem("0x3f(C相组合无功1)");
        ui->listWidget_2->addItem("0x40(C相组合无功2)");
        ui->listWidget_2->addItem("0x41(C相第1象限无功)");
        ui->listWidget_2->addItem("0x42(C相第2象限无功)");
        ui->listWidget_2->addItem("0x43(C相第3象限无功)");
        ui->listWidget_2->addItem("0x44(C相第4象限无功)");
        ui->listWidget_2->setCurrentRow(0);

        ui->listWidget_3->clear();
        ui->listWidget_3->addItem("0x00(有功总电能)");
        ui->listWidget_3->addItem("0x01(费率1电能)");
        ui->listWidget_3->addItem("0x02(费率2电能)");
        ui->listWidget_3->addItem("0x03(费率3电能)");
        ui->listWidget_3->addItem("0x04(费率4电能)");
        ui->listWidget_3->addItem("0xff(数据块)");
        ui->listWidget_3->setCurrentRow(0);

        ui->listWidget_4->clear();
        ui->listWidget_4->addItem("当前值");
        ui->listWidget_4->addItem("上1次");
        ui->listWidget_4->addItem("上2次");
        ui->listWidget_4->addItem("上3次");
        ui->listWidget_4->addItem("上4次");
        ui->listWidget_4->addItem("上5次");
        ui->listWidget_4->addItem("上6次");
        ui->listWidget_4->addItem("上7次");
        ui->listWidget_4->addItem("上8次");
        ui->listWidget_4->addItem("上9次");
        ui->listWidget_4->addItem("上10次");
        ui->listWidget_4->addItem("上11次");
        ui->listWidget_4->addItem("上12次");
        ui->listWidget_4->setCurrentRow(0);

    }
    else if(ui->listWidget->currentRow()==2)
    {
        ui->listWidget_2->clear();
        ui->listWidget_2->addItem("0x01(电压)");
        ui->listWidget_2->addItem("0x02(电流)");
        ui->listWidget_2->addItem("0x03(瞬时有功功率)");
        ui->listWidget_2->addItem("0x04(瞬时无功功率)");
        ui->listWidget_2->addItem("0x05(瞬时视在功率)");
        ui->listWidget_2->addItem("0x06(功率因数)");
        ui->listWidget_2->addItem("0x07(相角)");
        ui->listWidget_2->addItem("0x80(零线电流)");
        ui->listWidget_2->setCurrentRow(0);
    }
    else if(ui->listWidget->currentRow()==3)
    {
        ui->listWidget_2->clear();
        ui->listWidget_3->clear();
        ui->listWidget_4->clear();
    }
    else if(ui->listWidget->currentRow()==4)
    {
        ui->listWidget_2->clear();
        ui->listWidget_3->clear();
        ui->listWidget_4->clear();
        ui->listWidget_2->addItem("(0x00)运行参数");

        ui->listWidget_3->addItem("(0x04)地址常数");
        ui->listWidget_3->addItem("(0x12)日冻结时间");

        ui->listWidget_4->addItem("(0x01)通信地址");
        ui->listWidget_4->addItem("(0x02)表号");
        ui->listWidget_4->addItem("(0x03)资产管理号");
        ui->listWidget_4->addItem("(0x04)额定电压");
        ui->listWidget_4->addItem("(0x05)额定电流");
        ui->listWidget_4->addItem("(0x06)最大电流");
        ui->listWidget_4->addItem("(0x07)有功准确度等级");
        ui->listWidget_4->addItem("(0x08)无功准确度等级");
        ui->listWidget_4->addItem("(0x09)有功脉冲常数");
        ui->listWidget_4->addItem("(0x10)无功脉冲常数");
        ui->listWidget_4->addItem("(0x11)电表型号");
        ui->listWidget_4->addItem("(0x12)生产日期");
        ui->listWidget_4->addItem("(0x13)协议版本号");
        ui->listWidget_4->addItem("(0x14)客户编号");

        ui->listWidget_2->setCurrentRow(0);
        ui->listWidget_3->setCurrentRow(0);
        ui->listWidget_4->setCurrentRow(0);

    }
    else if(ui->listWidget->currentRow()==5)
    {
        ui->listWidget_2->clear();
        ui->listWidget_2->addItem("(0x00)定时冻结");
        ui->listWidget_2->addItem("(0x01)瞬时冻结");
        ui->listWidget_2->addItem("(0x02)时区切换冻结");
        ui->listWidget_2->addItem("(0x03)日时段切换冻结");
        ui->listWidget_2->addItem("(0x04)整点冻结(协议未有)");
        ui->listWidget_2->addItem("(0x05)费率切换冻结（协议未有）");
        ui->listWidget_2->addItem("(0x06)日冻结");
        ui->listWidget_2->addItem("(0x07)阶梯切换冻结（协议未有）");

        ui->listWidget_3->clear();
        ui->listWidget_3->addItem("(0x00)冻结时间");
        ui->listWidget_3->addItem("(0x01)正向有功电量");
        ui->listWidget_3->addItem("(0x02)反向有功电量");
        ui->listWidget_3->addItem("(0x03)组合无功1电量");
        ui->listWidget_3->addItem("(0x04)组合无功2电量");
        ui->listWidget_3->addItem("(0x05)一象限无功电量");
        ui->listWidget_3->addItem("(0x06)二象限无功电量");
        ui->listWidget_3->addItem("(0x07)三象限无功电量");
        ui->listWidget_3->addItem("(0x08)四象限无功电量");
        ui->listWidget_3->addItem("(0x09)正向有功最大需量");
        ui->listWidget_3->addItem("(0x0a)反向有功最大需量");
        ui->listWidget_3->addItem("(0x10)有功无功功率");
        ui->listWidget_3->addItem("(0xff)数据块");

        ui->listWidget_4->clear();
        for(int i=1;i<=60;i++)
        {
            QByteArray arry;
            arry.resize(1);
            arry.data()[0]=i;
            QString temp=arry.toHex();
            QString itemStr=QString("(0x%0)上%1次").arg(temp).arg(i);
            ui->listWidget_4->addItem(itemStr);
        }
        ui->listWidget_4->addItem("数据块");

        ui->listWidget_2->setCurrentRow(0);
        ui->listWidget_3->setCurrentRow(0);
        ui->listWidget_4->setCurrentRow(0);
    }
}

void MainWindow::ListWidget3_ItemSelectChanged()
{
    if(ui->listWidget->currentRow()==0x04)
    {
        if(ui->listWidget_3->currentRow()==0x00)
        {
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("(0x01)通信地址");
            ui->listWidget_4->addItem("(0x02)表号");
            ui->listWidget_4->addItem("(0x03)资产管理号");
            ui->listWidget_4->addItem("(0x04)额定电压");
            ui->listWidget_4->addItem("(0x05)额定电流");
            ui->listWidget_4->addItem("(0x06)最大电流");
            ui->listWidget_4->addItem("(0x07)有功准确度等级");
            ui->listWidget_4->addItem("(0x08)无功准确度等级");
            ui->listWidget_4->addItem("(0x09)有功脉冲常数");
            ui->listWidget_4->addItem("(0x10)无功脉冲常数");
            ui->listWidget_4->addItem("(0x11)电表型号");
            ui->listWidget_4->addItem("(0x12)生产日期");
            ui->listWidget_4->addItem("(0x13)协议版本号");
            ui->listWidget_4->addItem("(0x14)客户编号");
        }
        else if(ui->listWidget_3->currentRow()==0x01)
        {
            ui->listWidget_4->clear();
            ui->listWidget_4->addItem("(0x03)日冻结时间");
        }
        ui->listWidget_4->setCurrentRow(0x00);
    }
}

void MainWindow::ReadAdressData()
{
    //组包
    QByteArray sendData;
    sendData.clear();

    sendData.append(0x68);

    for(int i=0;i<=5;i++)
        sendData.append(0xaa);

    sendData.append(0x68);
    sendData.append(0x13);
    sendData.append((uchar)0x00);
    AddCheckSum(sendData);

    //发送
    dlt645[0].port.write(sendData);
    dlt645[0].port.waitForBytesWritten();
    //读取
    QByteArray recvData;
    ReadData(recvData,0);
    //解析
    ParseDateData(recvData);

}

void MainWindow::WriteAdressData()
{
    QByteArray sendData;
    sendData.clear();
    sendData.append(0x68);

    for(int i=0;i<=5;i++)
    {
        sendData.append(0xaa);
    }

    sendData.append(0x68);
    sendData.append(0x15);
    sendData.append(0x06);

    QString writeAddress=ui->lineEdit_5->text();
    if(writeAddress.length()<12)
    {
        QByteArray tmp;
        tmp.resize(12-writeAddress.length());
        tmp.fill(0x30);
        writeAddress.prepend(tmp);
        qDebug()<<"写入地址字符串->："<<writeAddress;
    }

    bool ok;
    for(int i=0;i<=5;i++)
    {
        QString tmpStr=writeAddress.right(2);
        uchar number=tmpStr.toInt(&ok,16)+0x33;
        writeAddress=writeAddress.remove((5-i)*2,2);
        sendData.append(number);
        qDebug()<<number<<sendData.toHex();
    }
    AddCheckSum(sendData);

    dlt645[0].port.write(sendData);
    dlt645[0].port.waitForBytesWritten();

    QByteArray recvData;
    ReadData(recvData,0);
}

void MainWindow::WriteGeneralData()
{
    qDebug()<<__FUNCTION__;

    QByteArray sendData;
    sendData.clear();
    //0x68
    sendData.append(0x68);

    //地址
    QByteArray temp,temp2;
    temp2.clear();
    temp2.resize(6);
    temp=QByteArray::fromHex(ui->lineEdit->text().toUtf8());
    for(int i=0;i<=5;i++)
    {
        temp2.data()[i]=temp.data()[5-i];
    }
    sendData.append(temp2);

    //0x68 0x14
    sendData.append(0x68);
    sendData.append(0x14);

    //数据长度
    uchar L=12+ui->lineEdit_2->text().length()/2;
    sendData.append(L);

    //DI0
    GetByteArray4(sendData);

    //DI1
    GetByteArray3(sendData);

    //DI2
    GetByteArray2(sendData);

    //DI3
    GetByteArray1(sendData);

    //授权等级
    uchar authorType=ui->lineEdit_4->text().toInt();
    authorType=authorType+0x33;
    sendData.append(authorType);

    //密码
    temp=QByteArray::fromHex(ui->lineEdit_3->text().toUtf8());
    temp2.clear();
    temp2.resize(3);
    for(int i=0;i<=2;i++)
    {
        temp2.data()[i]=temp.data()[2-i]+0x33;
    }
    sendData.append(temp2);
    //操作者代码
    sendData.append(0x00+0x33);
    sendData.append(0x00+0x33);
    sendData.append(0x00+0x33);
    sendData.append(0x00+0x33);

    //数据
    QString writeData=ui->lineEdit_2->text();
    int length=ui->lineEdit_2->text().length()/2;
    bool ok=false;

    for(int i=0;i<=length-1;i++)
    {
        QString tmpStr=writeData.right(2);
        uchar number=tmpStr.toInt(&ok,16)+0x33;
        writeData=writeData.remove((length-1-i)*2,2);
        sendData.append(number);
    }

    AddCheckSum(sendData);

    dlt645[0].port.write(sendData);
    qDebug()<<"发送的十六进制数据为"<<sendData.toHex();
    dlt645[0].port.waitForBytesWritten();

    QByteArray recvData;
    ReadData(recvData,0);
}

void MainWindow::BroadCasetTime()
{
    qDebug()<<__FUNCTION__;
    QByteArray sendData;
    sendData.clear();

    sendData.append(0x68);

    for(int i=1;i<=6;i++)
        sendData.append(0x99);

    sendData.append(0x68);
    sendData.append(0x08);
    sendData.append(0x06);

    QDateTime now=QDateTime::currentDateTime();
    qDebug()<<now.toString("yyyy-MM-dd hh:mm:ss");
    uchar year,mounth,day,hour,minute,second;
    bool ok;
    year=QString("0x"+QString::number(now.date().year()).right(2)).toInt(&ok,16);
    qDebug()<<now.date().year()<<QString("0x"+QString::number(now.date().year()).right(2));
    mounth=QString("0x"+QString::number(now.date().month()).right(2)).toInt(&ok,16);
    day=QString("0x"+QString::number(now.date().day()).right(2)).toInt(&ok,16);

    hour=QString("0x"+QString::number(now.time().hour()).right(2)).toInt(&ok,16);
    minute=QString("0x"+QString::number(now.time().minute()).right(2)).toInt(&ok,16);
    second=QString("0x"+QString::number(now.time().second()).right(2)).toInt(&ok,16);

    qDebug()<<year<<mounth<<day<<hour<<minute<<second;


    sendData.append(second+0x33);
    sendData.append(minute+0x33);
    sendData.append(hour+0x33);
    sendData.append(day+0x33);
    sendData.append(mounth+0x33);
    sendData.append(year+0x33);

    AddCheckSum(sendData);

    dlt645[0].port.write(sendData);
    qDebug()<<"发送的十六进制数据为"<<sendData.toHex();
    dlt645[0].port.waitForBytesWritten();

    QByteArray recvData;
    ReadData(recvData,0);

}

void MainWindow::BroadCasetTimeByZhiDing()
{
    uchar second,minute,hour,day,month,year;
    QByteArray sendData;
    sendData.clear();

    sendData.append(0x68);

    for(int i=1;i<=6;i++)
        sendData.append(0x99);

    sendData.append(0x68);
    sendData.append(0x08);
    sendData.append(0x06);

    QString tmp=QString::number(ui->spinBox_5->value());
    tmp="0x"+tmp;
    bool ok;
    second=tmp.toInt(&ok,16);

    tmp=QString::number(ui->spinBox_6->value());
    tmp="0x"+tmp;
    minute=tmp.toInt(&ok,16);

    tmp=QString::number(ui->spinBox_7->value());
    tmp="0x"+tmp;
    hour=tmp.toInt(&ok,16);

    tmp=QString::number(ui->spinBox_4->value());
    tmp="0x"+tmp;
    day=tmp.toInt(&ok,16);

    tmp=QString::number(ui->spinBox_3->value());
    tmp="0x"+tmp;
    month=tmp.toInt(&ok,16);

    tmp=QString::number(ui->spinBox_2->value());
    tmp="0x"+tmp;
    year=tmp.toInt(&ok,16);

    sendData.append(second+0x33);
    sendData.append(minute+0x33);
    sendData.append(hour+0x33);
    sendData.append(day+0x33);
    sendData.append(month+0x33);
    sendData.append(year+0x33);

    AddCheckSum(sendData);

    dlt645[0].port.write(sendData);
    //广播指令，无返回
}

